function Calculator() {
    this.method = {};
    this.method['+'] = (a, b) => a + b;
    this.method['-'] = (a, b) => a - b;
    this.calculator = function (str) {
        let op = str.split(' ');
        let num1 = +op[0];
        let num2 = +op[2];
        if (op[1] == '+') {
            return num1 + num2;
        } else if (op[1] == '-') {
            return num1 - num2;
        } else if (this.method[op[1]] != null) {
            return this.method[op[1]](num1, num2);
        }
    };
    this.addMethod = function(name, func) {
        this.method[name] = func;
    }
}


let calc = new Calculator;

alert(calc.calculator("3 + 7"));

let powerCalc = new Calculator;
powerCalc.addMethod("*", (a, b) => a * b);
powerCalc.addMethod("/", (a, b) => a / b);
powerCalc.addMethod("**", (a, b) => a ** b);

alert(powerCalc.calculator("2 ** 3")); 
alert(powerCalc.calculator("8 / 2"));
alert(powerCalc.calculator("2 * 3"));